
!  --------------------------------------------------
!  Silverfrost FTN95 for Microsoft Visual Studio
!  Fixed Format FTN95 Source File
!  --------------------------------------------------

!program TesRegFalsi
!implicit none
!implicit none
!real*8 epsilon, answer, x1, x2
!integer*2 count
!parameter (epsilon = 1.E-5)
!parameter (x1=111*1.E-3)
!parameter (x2=999*1.E-3)
!call metoderegulafalsi (epsilon,x1,x2,answer,count)
!print*,answer
!print*,count
!pause
!end


subroutine metoderegulafalsi (eps,a,b,jawaban,iter)
implicit none
real*8 a,b,eps,jawaban,c,temp1,temp2,f
integer*2 iter
iter = 0
temp1 = a
temp2 = b

do while (abs (temp1-temp2) > eps)
    iter = iter +1
    c = temp2-((f(temp2)*(temp2-temp1))/(f(temp2)-f(temp1)))
    if(abs(f(c)) < 1.E-6) then
        temp1=c
        temp2=c
        jawaban = c
        exit  
    else if ((f(temp1)*f(c)) < 0) then
            temp2=c
    else
            temp1=c
    end if        
end do
end

!real*8 function f(x)
!implicit none
!real*8 x
!f = ((x*((2.1-(0.5*x))**0.5)) / ((1-x)*((1.1-(0.5*x))**0.5))) - 3.69
!f = tan(x)-x+1
!end